package com.bgs.eat.commodityOrder.controller;

import com.bgs.eat.commodity.entity.CommodityEntity;
import com.bgs.eat.commodityOrder.entity.CommodityOrderEntity;
import com.bgs.eat.commodityOrder.service.CommodityOrderService;
import com.bgs.eat.config.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * @ClassName CommodityOrderController
 * @Description TODO
 * @Author lzy
 * @Date 2022/10/19 18:56
 **/
@RestController
@CrossOrigin
@RequestMapping("/commodityOrder")
public class CommodityOrderController {

    @Autowired
    CommodityOrderService commodityOrderService;

    /**
    * @Description 用户提交商品订单（门户用户端）
    * @Author lzy
    * @Date 2022/10/31 10:45
    * @Return com.bgs.eat.config.CommonResult
    * @param commodityOrderEntity
    */
    @PostMapping("/submitCommodityOrder")
    public CommonResult submitCommodityOrder(@RequestBody CommodityOrderEntity commodityOrderEntity){
        return commodityOrderService.submitCommodityOrder(commodityOrderEntity);
    }


    /**
    * @Description 提交订单时获取预计到达时间（门户用户端）
    * @Author lzy
    * @Date 2022/10/29 9:57
    * @Return com.bgs.eat.config.CommonResult
    * @param userLat
    * @param userLng
    * @param shopLat
    * @param shopLng
    * @param sumMealTime 总出餐时间
    */
    @GetMapping("/getDeliveryTime")
    public CommonResult getDeliveryTime(String userLat, String userLng, String shopLat, String shopLng, Integer sumMealTime){
        return commodityOrderService.getDeliveryTime(userLat, userLng, shopLat, shopLng, sumMealTime);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据当前骑手所在县查询所有订单
     * @Date: 2022/10/21 15:25
     * @Return: com.bgs.eat.config.CommonResult
     * @Param: [phone]
     */

    @GetMapping("/findAllOrders")
    public CommonResult findAllOrders(String phone,String riderLat,String riderLng,Integer id,Integer status) throws ParseException {
        return commodityOrderService.findAllOrders(phone,riderLat,riderLng,id,status);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 骑手抢单/取货/配送完成
     * @Date: 2022/10/24 8:45
     * @Return: com.bgs.eat.config.CommonResult
     * @Param: [id, orderId]
     */

    @GetMapping("/snatchOrders")
    public CommonResult snatchOrders(Integer id,Integer orderId,Integer type,String riderLat,String riderLng) throws ParseException {
        return commodityOrderService.snatchOrders(id,orderId,type,riderLat,riderLng);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 每过一分钟减剩余时间一分钟
     * @Date: 2022/10/25 15:10
     * @Return: com.bgs.eat.config.CommonResult
     * @Param: [commodityOrderEntity]
     */

    @PostMapping("/updateTime")
    public CommonResult updateTime(@RequestBody CommodityOrderEntity commodityOrderEntity){
        return commodityOrderService.updateTime(commodityOrderEntity);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据骑手ID查询今日订单
     * @Date: 2022/10/27 15:32
     * @Return: com.bgs.eat.config.CommonResult
     * @Param: [riderId]
     */

    @GetMapping("/getTodayOrder")
    public CommonResult getTodayOrder(Integer riderId){

        return commodityOrderService.getTodayOrder(riderId);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 查询历史订单
     * @Date: 2022/10/28 9:19
     * @Return: com.bgs.eat.config.CommonResult
     * @Param: [id, status, stutus1]
     */

    @GetMapping("/findAllhistoryOrders")
    public CommonResult findAllhistoryOrders(Integer id,Integer status,Integer stutus1){
        return commodityOrderService.findAllhistoryOrders(id,status,stutus1);
    }

    /**
    * @Author gpd
    * @Description 查询对应配送状态的订单信息
    * @Date 2022-10-31 下午 03:53
    * @Return com.bgs.eat.config.CommonResult

    */
    @GetMapping("/getCommodityOrderList")
    public CommonResult getCommodityOrderList(Integer shopId,Integer distributionStatus){
        return CommonResult.ok(commodityOrderService.getCommodityOrderList(shopId,distributionStatus));
    }

    /**
    * @Author gpd
    * @Description 商家选择配送方式
    * @Date 2022-11-01 上午 11:38
    * @Return com.bgs.eat.config.CommonResult

    */
    @PostMapping("/choseDeliveryMethod")
    public CommonResult choseDeliveryMethod(@RequestBody CommodityOrderEntity commodityOrderEntity){
        return CommonResult.ok(commodityOrderService.choseDeliveryMethod(commodityOrderEntity));
    }
}
